package cranim.graphics;

import cranim.Constants;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Benedikt
 */
public class AnimWindow extends Canvas implements Constants{
    
    private BufferStrategy bStrategy;
            
    public AnimWindow(){
            
            JFrame container = new JFrame(ANIM_TITLE);            
            JPanel panel = (JPanel) container.getContentPane();
            panel.setPreferredSize(ANIM_DIM);
            panel.setLayout(null);            
            setBounds(0,0,ANIM_WIDTH,ANIM_HEIGHT);
            panel.add(this);
            panel.setBackground(Color.black);
            setIgnoreRepaint(true);
            container.pack();
            container.setResizable(false);
            container.setVisible(true);
            
            createBufferStrategy(2);
            bStrategy = getBufferStrategy();
    }
    
    public void drawAll(ArrayList entities){
        Graphics2D g = (Graphics2D) bStrategy.getDrawGraphics();
        g.setColor(Color.black);
        g.fillRect(0,0,ANIM_WIDTH,ANIM_HEIGHT);
        for (int i=0;i<entities.size();i++) {
            Entity entity = (Entity) entities.get(i);
            entity.draw(g);
        }
        g.dispose();
        bStrategy.show();
    }
}
